import { CONFIG } from '@/constants';
import { PlusOutlined } from '@ant-design/icons';
import { Button, GetProp, Upload, UploadProps, message } from 'antd';
import { useEffect } from 'react';

type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0];
const FormVideos: React.FC<IBuildForm.Params> = (props) => {
    const beforeUpload = (file: FileType) => {
        const isJpgOrPng =
            file.type === 'video/mp4' ||
            file.type === 'video/avi' ||
            file.type === 'video/wmv' ||
            file.type === 'video/mpeg';
        if (!isJpgOrPng) {
            message.error('You can only upload mp4/avi/wmv/mpeg file!');
        }
        const isLt2M = file.size / 1024 / 1024 < 10;
        if (!isLt2M) {
            message.error('Image must smaller than 10MB!');
        }
        return (isJpgOrPng && isLt2M) || Upload.LIST_IGNORE;
    };
    const uploadButton = (
        <Button>
            <PlusOutlined />
            Upload
        </Button>
    );

    useEffect(() => {}, []);
    return (
        <>
            <Upload
                {...props}
                beforeUpload={beforeUpload}
                action={CONFIG.HTTP_REQUEST_URL + '/common/upload'}
            >
                {uploadButton}
            </Upload>
        </>
    );
};
export default FormVideos;
